package com.hnrd.crud.shiro;

import org.apache.shiro.SecurityUtils;

import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Component;

@Component
public class MyShiroManager {
	
	public static Subject setMyRealm(MyRealm myRealm) {
		DefaultSecurityManager defaultSecurityManager = new DefaultSecurityManager();
		/**
		 * 设置用户权限判断对象
		 */
		defaultSecurityManager.setRealm(myRealm);
		/**
		 * 为realm设置加密方法（MD5），加密次数
		 */
		HashedCredentialsMatcher Matcher =new HashedCredentialsMatcher();
		Matcher.setHashAlgorithmName("md5");
		Matcher.setHashIterations(5);
		myRealm.setCredentialsMatcher(Matcher);
		/**
		 * 放入工具类
		 */
		SecurityUtils.setSecurityManager(defaultSecurityManager);
		/**
		 * 通过工具类生成对象
		 */
		Subject subject =SecurityUtils.getSubject();
		return subject;
	}
	
	
}
